package com.lancoo.znbkxx.teacher.ui.fragment

import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.base.BaseVMFragment
import com.lancoo.znbkxx.teacher.databinding.FmtPaperTabBinding
import com.lancoo.znbkxx.teacher.viewmodel.PaperViewModel
import kotlinx.android.synthetic.main.fmt_paper_tab.*

/**
 * Created by wealive on 2021/3/26.
 *
 *
 */
class TabPaperFragment : BaseVMFragment<PaperViewModel, FmtPaperTabBinding>() {
    override fun providerVMClass(): Class<PaperViewModel>? {
        return PaperViewModel::class.java
    }

    override fun providerContext(): Any? {
        return this
    }

    override fun setLayoutID(): Int {
        return R.layout.fmt_paper_tab
    }

    override fun initView() {
        vp_paper.isUserInputEnabled = false
        vp_paper.offscreenPageLimit = 2
        vp_paper.adapter = object : FragmentStateAdapter(childFragmentManager, lifecycle) {
            override fun getItemCount(): Int {
                return 3
            }

            override fun createFragment(position: Int): Fragment {
                return BasicPaperFragment().apply {
                    arguments = bundleOf(Pair("layer", position),Pair("from", "basic"))
                }
            }
        }
        val tabs = arrayOf("基础复习", "拓展复习", "模考作业")
        TabLayoutMediator(tbl, vp_paper) { tab, position ->
            tab.text = tabs[position]
        }.attach()
    }
}